<?php /* Smarty version 2.6.26, created on 2011-02-27 06:57:13
         compiled from admin/manage.html */ ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "admin/header.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
<div class="container">
	<div class="floattop">
		<div class="itemtitle">
			<h3>管理员</h3>
			<ul class="tab1">
				<li class="current"><a href="?act=add_manage"><span>添加管理员</span></a></li>
			</ul>
		</div>
	</div>
	<div class="floattopempty"></div>
	<?php if ($this->_tpl_vars['add_manage']): ?>
		<form id="manager_add_form" action="" method="post">
			<table class="tb tb2">
				<tbody>

					<tr>
						<td class="td27" colspan="2">管理员：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="text" value="" name="admin_name">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">密码：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="password" value="" id="admin_pass" name="admin_pass">
						</td>
						<td class="vtop tips2"></td>
					</tr>	
					<tr>
						<td class="td27" colspan="2">确认密码：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="password" value="" name="admin_vpass">
						</td>
						<td class="vtop tips2"></td>
					</tr>									
					<tr>
						<td colspan="15">
							<input type="hidden" name="act" value="add">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	<?php elseif ($this->_tpl_vars['edit_manage']): ?>
		<form id="manager_edit_form" action="" method="post">
			<table class="tb tb2">
				<tbody>

					<tr>
						<td class="td27" colspan="2">旧密码：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="password" value="" name="old_pass">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">新密码：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="password" value="" id="new_pass" name="new_pass">
						</td>
						<td class="vtop tips2"></td>
					</tr>	
					<tr>
						<td class="td27" colspan="2">确认密码：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="password" value="" name="new_vpass">
						</td>
						<td class="vtop tips2"></td>
					</tr>									
					<tr>
						<td colspan="15">
							<input type="hidden" name="act" value="save">
							<input type="hidden" name="admin_id" value="<?php echo $this->_tpl_vars['admin_id']; ?>
">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		</form>			
	<?php else: ?>
		<div class="list-div">
		<table class="tb tb2" cellspacing="1" cellpadding="3">
		<tbody>
			<tr class="header">
				<th>编号</th>
				<th>管理员</th>
				<th>操作</th>
			</tr>
			<?php $_from = $this->_tpl_vars['admin_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['al']):
?>
			<tr class="td-cls">
				<td><?php echo $this->_tpl_vars['al']['admin_id']; ?>
</td>
				<td><?php echo $this->_tpl_vars['al']['admin_name']; ?>
</td>
				<td><span class="operation"><a href="?act=edit_manage&admin_id=<?php echo $this->_tpl_vars['al']['admin_id']; ?>
" class="edit">修改</a></span><span class="operation"><?php if ($this->_tpl_vars['al']['admin_name'] != 'admin'): ?><a href="#" class="del">删除</a><?php endif; ?></span></td>
			</tr>
			<?php endforeach; endif; unset($_from); ?>
		</tbody>
	</table>
	</div>		
	<?php endif; ?>
	
 </div>
 <script type="text/javascript">

$(document).ready(function(){
	$('#manager_add_form').validate({
		rules: {
			admin_name: {
				required: true,
				minlength: 3
			},
			admin_pass: {
				required: true,
				minlength: 6
			},
			admin_vpass: {
				required: true,
				equalTo: '#admin_pass'
			}
		},
		messages: {
			admin_name: {
				required: '请输入管理员',
				minlength: '至少3个字符'
			},
			admin_pass: {
				required: '请输入密码',
				minlength: '至少6个字符'
			},
			admin_vpass: {
				required: '请输入确认密码',
				equalTo: '两次输入密码不一致'
			}
											
		},
		success:function(label) {
			label.html(' ').addClass('right');
		},		
		submitHandler:function() {
			add_submit();
		}
		
	});
	
	
	
	$('#manager_edit_form').validate({
		rules: {
			old_pass: {
				required: true,
				minlength: 6
			},			
			new_pass: {
				required: true,
				minlength: 6
			},			
			
			new_vpass: {
				required: true,
				equalTo: '#new_pass'
			}

		},
		messages: {
			old_pass: {
				required: '不能为空',
				minlength: '至少6个字符'
			},
			new_pass: {
				required: '不能为空',
				minlength: '至少6个字符'
			},
			new_vpass: {
				required: '请输入确认密码',
				equalTo: '两次输入密码不一致'
			}
											
		},
		
		submitHandler:function() {
			edit_submit();
		}
		
	});	
	
	
	
});

var add_submit = function() {
	var pam = $('#manager_add_form').serialize();
	$.ajax({
		type: "GET",
		url: "manage.php",
		data: pam,
		success: function(data) {
			if(data == 'ok') {
				alert('添加成功！');
				setTimeout(function(){window.location.reload();}, 200);
			}
			if(data == 'haved') {
				alert('管理员已存在！');
			}
		}
	});
	
}



var edit_submit = function() {
	var pam = $('#manager_edit_form').serialize();
	$.ajax({
		type: "GET",
		url: "manage.php",
		data: pam,
		success: function(data) {
			if(data == 'ok') {
				alert('修改成功！');
				setTimeout(function(){window.location.reload();}, 200);
			}
			if(data == 'oldpass_error') {
				alert("旧密码错误！");
			}
		}
	});
	
}


$('.del').click(function(){
	if(confirm('确认删除？')) {
		var obj = $(this);
		var admin_id = obj.parents('tr').find('td').eq(0).text();
		$.get('manage.php', {act:'del', admin_id:admin_id}, function(data){
			if(data == 1) {
				alert('删除成功');
				obj.parents('tr').remove()
			}
		});	
	}
});
</script>
 <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "admin/footer.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>	